package org.hackystat.devcathlon.ui.page.scoreboard.commentpanel;

import java.util.ArrayList;
import java.util.List;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.repeater.Item;
import org.apache.wicket.markup.repeater.data.DataView;
import org.apache.wicket.markup.repeater.data.ListDataProvider;
import org.hackystat.devcathlon.engine.commentary.Comment;
import org.hackystat.devcathlon.engine.match.Match;

/**
 * Display Match comments in the Comments panel.
 * 
 * @author Daniel Arakaki
 */
public class CommentPanel extends Panel {

  /** Support serialization. */
  private static final long serialVersionUID = 1L;

  /**
   * Sets up the comment panel.
   * 
   * @param id The Wicket id from the html file.
   * @param match A chosen match.
   */
  public CommentPanel(String id, Match match) {
    super(id);
    add(new Label("matchNameHeader", match.getName()));
    
    List<Comment> commentList = new ArrayList<Comment>(match.getComments());
    
    DataView commentView = new DataView("commentList", new ListDataProvider(commentList)) {

      /** Support serialization. */
      private static final long serialVersionUID = 1L;

      @Override
      protected void populateItem(Item item) {
        Comment commentItem = (Comment) item.getModelObject();
        item.add(new Label("comments", commentItem.getComment()));
      }
      
    };
    add(commentView);
  }

}
